﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace LibMS.Models
{
    public static class MSSqlConnection
    {
        /// <summary>
        /// Get MSSqlConntion
        /// </summary>
        public static IDbConnection GetConnection()
        {
            var connectionStr = GetConnectionString();
            if (!string.IsNullOrEmpty(connectionStr))
            {
                return new SqlConnection(connectionStr);
            }
            throw new Exception("Connection string is null");//connectionStr is null
        }

        private static string GetConnectionString()
        {
            try
            {
                return ConfigurationManager.ConnectionStrings["LibMSConnectionString"].ConnectionString;
            }
            catch (ConfigurationErrorsException)
            {
                return null;
            }
        }
    }
}